package com.example.springbootdemo.config;

import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

/**
 * 这是一个线程工具类，继承与springboot的一个工具，防止忘记
 * @author 84246
 */
@Component
public class MyThreadPoolTaskExecutor extends ThreadPoolTaskExecutor {
    @Resource
    @Lazy
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    public String getS(long time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "getSring";
    }

    public void threadTest() throws Exception {
        CompletableFuture.supplyAsync(() -> new MyThreadPoolTaskExecutor().getS(3000), threadPoolTaskExecutor.getThreadPoolExecutor());
    }
}
